$(document).ready(function(){    
	$('.birthday-ajax-search').focus(function(){
		var url = $(this).attr('url');
		$(this).keyup(function() {
			var search_keyword= $(this).val();
			initialize_search_keyword(search_keyword,url);
		});
	});
});


function initialize_search_keyword(keyword,url)
{
	var posting = $.post( url, { s: keyword } );
	posting.done(function( data )
	{
		console.log(data);
		data=JSON.parse(data);
		var html = '<table><thead><tr><td>Fullname</td><td>Level Desc</td><td>ID Number</td><td>Date Of Birth</td></tr></thead>';
		if(data != false)
		{
			$.each(data, function(k, v){
				html +="<tr><td>"+v.fullname+"</td><td>"+v.level_desc+"</td><td>"+v.idno+"</td><td>"+v.dob+"</td></tr>";
			 });
			
		}else{
			 html += '<tr><td colspan="4">Search for keyword ('+keyword+') has returned no results</td></tr>';
		}
			html += '</table>';
		$("#birthday-ajax-search-items" ).empty().append(html);	
	});
		
}